package com.xbongbong.pro.rabbitmq.service.impl;

import com.alibaba.dingtalk.openapi.helper.Env;
import com.alibaba.dingtalk.openapi.newmessage.entity.OA;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushEntity;
import com.xbongbong.paas.domain.entity.PaasMenuEntity;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.util.URLEncodeUtils;
import com.xbongbong.paas.toolbox.util.UrlUtil;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.MessageErrorCodeEnum;
import com.xbongbong.pro.enums.smartsettings.enums.AiAssistantPushTypeEnum;
import com.xbongbong.pro.message.enums.MessageWebPcUrlEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.pojo.PushRefTypePojo;
import com.xbongbong.pro.message.pojo.dto.MessageRabbitMqDTO;
import com.xbongbong.pro.message.service.PushService;
import com.xbongbong.pro.rabbitmq.service.AiAssistantService;
import com.xbongbong.saas.enums.AiAssistantDingtalkPageUrlEnum;
import com.xbongbong.saas.enums.ListGroupEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: hongxiao
 * @date: 2019-11-18 15:11
 */

@Service("aiAssistantService")
public class AiAssistantServiceImpl implements AiAssistantService {
    @Resource
    private PushService pushService;
    @Resource
    private ProBaseConfig proBaseConfig;
    @Resource
    private PaasMenuModel paasMenuModel;

    @Override
    public void insertPushData(MessageRabbitMqDTO messageRabbitMqDTO, AiAssistantPushTypeEnum pushTypeEnum) throws XbbException {
        String corpid = messageRabbitMqDTO.getCorpid();
        List<String> userIds = messageRabbitMqDTO.getUserIds();
        List<Long> refIds = messageRabbitMqDTO.getRefIds();
        if (StringUtil.isEmpty(corpid)) {
            throw new XbbException(MessageErrorCodeEnum.API_ERROR_380007);
        }
        if (userIds == null || userIds.size() == 0) {
            throw new XbbException(MessageErrorCodeEnum.API_ERROR_380005);
        }
        if (userIds.size() > 100) {
            throw new XbbException(MessageErrorCodeEnum.API_ERROR_380008);
        }
        if (refIds == null || refIds.size() == 0) {
            throw new XbbException(MessageErrorCodeEnum.API_ERROR_380006);
        }

        Integer isRemind = messageRabbitMqDTO.getRemind();
        Long pushTime = messageRabbitMqDTO.getPushTime();
        String title = messageRabbitMqDTO.getTitle();
        String content = messageRabbitMqDTO.getContent();

        List<OA.Body.Form> formList = messageRabbitMqDTO.getForm();

        PushRefTypePojo.Options options = messageRabbitMqDTO.getOptions();

        OA oaMessage = formatOaMessage(pushTypeEnum, title, content, formList, options, corpid);

        String type = formatRefType(pushTypeEnum, options);

        Long now = DateTimeUtil.getInt();
        //以下备注的都是弃用的  @date 2019/2/26 19:37  @author 魏荣杰
        PushEntity pushEntity = new PushEntity();
        pushEntity.setCorpid(corpid);
        pushEntity.setRefEntity(pushTypeEnum.getCode());
        // TODO: 2019/3/1 refid 待优化
        pushEntity.setRefId(refIds.get(0));
        pushEntity.setRefArray(JSONObject.toJSONString(refIds));
        //用于标记web端消息跳转方式
        pushEntity.setRefType(type);
        pushEntity.setType(pushTypeEnum.getCode());
        pushEntity.setSubType(pushTypeEnum.getSubCode());
        pushEntity.setPushObject(JSONObject.toJSONString(userIds));
        pushEntity.setMsg(JSONObject.toJSONString(oaMessage));
        pushEntity.setPushTime(pushTime);
        pushEntity.setIsPush(0);
        pushEntity.setIsRemind(isRemind);
        pushEntity.setAddTime(now);
        pushEntity.setUpdateTime(now);
        pushService.save(pushEntity);
    }

    private OA formatOaMessage(AiAssistantPushTypeEnum pushTypeEnum, String title, String content, List<OA.Body.Form> formList, PushRefTypePojo.Options options, String corpid) {
        String messageUrl = proBaseConfig.getPushFrontUrl() + "index.html?corpid=" + corpid + "&appid=" + Env.DING_XBB_APP_ID + "&dd_nav_bgcolor=ffff943e#";
        String pcMessageUrl = "dingtalk://dingtalkclient/page/link?url=";
        OA oaMessage = new OA();
        OA.Body body = new OA.Body();
        body.setForm(formList);
        body.setTitle(title);
        body.setContent(content);
        body.setAuthor(I18nMessageUtil.getMessage(I18nStringConstant.XBB_CRM));
        oaMessage.setBody(body);
        //OA消息封装
        switch (pushTypeEnum) {
            case CUSTOMER_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.CUSTOMER_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds(), options.getFormId());
                break;
            case CONTACT_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.CONTACT_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case OPPORTUNITY_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.OPPORTUNITY_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case CONTRACT_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.CONTRACT_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds(), options.getFormId());
                break;
            case WORK_REPORT_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.WORK_REPORT_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId());
                break;
            case REFUND_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.REFUND_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case QUOTATION_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.QUOTATION_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;


            case SUPPLIER_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.SUPPLIER_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case SUPPLIER_CONTACT_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.SUPPLIER_CONTACT_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case PURCHASE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PURCHASE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case RETURNED_PURCHASE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PURCHASE_RETURN_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;


            case INSTOCK_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.INSTOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case OUTSTOCK_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.OUTSTOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case ASSEMBLE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.ASSEMBLE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case TRANSFER_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.TRANSFER_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case INVENTORY_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.IINVENTORY_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;


            case BOMBILL_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.BOMBILL_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case PRODUCTION_ORDER_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PRODUCTION_ORDER_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;


            case PAYMENT_PLAN_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PAYMENT_PLAN_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case INVOICE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.INVOICE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;
            case PAY_PLAN_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PAY_PLAN_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds());
                break;

            /**
            case WORKORDER_PUSH:
                messageUrl += String.format(DingtalkPageUrlEnum.WORK_ORDER_DETAIL.getUrl(), options.getDataId(), options.getAppId(), options.getMenuId(), options.getFormId());
                break;
            */

            case PRODUCT_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PRODUCT_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds());
                break;
            case PRODUCT_STOCK_WARNING_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PRODUCT_STOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), ListGroupEnum.WARNING_SEARCH.getCode());
                break;
            case PRODUCT_STOCK_GUARANTEE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PRODUCT_STOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), ListGroupEnum.GUARANTEE_SEARCH.getCode());
                break;


            case WAIT_PURCHASE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.WAIT_PURCHASE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), options.getFormId());
                break;
            case WAIT_PRODUCE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.WAIT_PRODUCE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), options.getFormId());
                break;
            case WAIT_OUTSTOCK_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.WAIT_OUTSTOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), options.getFormId());
                break;
            case WAIT_INSTOCK_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.WAIT_INTSTOCK_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), options.getFormId());
                break;

            case MARKET_ACTIVITY_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.MARKET_ACTIVITY_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds(), options.getFormId());
                break;
            case CLUE_PUSH:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.CLUE_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getFormId(), options.getDataIds(), options.getFormId());
                break;
            case PAAS_PUSH:
                PaasMenuEntity menuEntity = paasMenuModel.getByKey(options.getMenuId(), corpid);
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.PAAS_LIST.getUrl(), options.getAppId(), options.getMenuId(), options.getDataIds(), Objects.isNull(menuEntity) ? "" : menuEntity.getName());
                break;
            case UNKNOWN:
                break;
            default:
                messageUrl += String.format(AiAssistantDingtalkPageUrlEnum.INDEX.getUrl(), corpid);
                break;
        }

        //非邀请在右侧打开
        if (!Objects.equals(pushTypeEnum, PushTypeEnum.INVITE_STAFF_PUSH)) {
            pcMessageUrl += URLEncodeUtils.encodeURL(messageUrl) + "&pc_slide=true";
        }

        oaMessage.setMessageUrl(messageUrl);
        oaMessage.setPcMessageUrl(pcMessageUrl);

        return oaMessage;
    }


    private String formatRefType(AiAssistantPushTypeEnum pushTypeEnum, PushRefTypePojo.Options options) throws XbbException {
        PushRefTypePojo pushRefTypePojo = new PushRefTypePojo();
        Map<String, Object> optionMap;
        switch (pushTypeEnum) {
            // 客户
            case CUSTOMER_PUSH:
                PushRefTypePojo.CommonListOptions customerListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, customerListOptions);
                optionMap = BeanUtil.convertBean2Map(customerListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.CUSTOMER_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.CUSTOMER_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(customerListOptions);
                break;
            // 联系人
            case CONTACT_PUSH:
                PushRefTypePojo.CommonListOptions contactListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, contactListOptions);
                optionMap = BeanUtil.convertBean2Map(contactListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.CONTACT_LIST.getType());

                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.CONTACT_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(contactListOptions);
                break;
            // 机会
            case OPPORTUNITY_PUSH:
                PushRefTypePojo.CommonListOptions opportunityListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, opportunityListOptions);
                optionMap = BeanUtil.convertBean2Map(opportunityListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.OPPORTUNITY_LIST.getType());

                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.OPPORTUNITY_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(opportunityListOptions);
                break;
            // 合同
            case CONTRACT_PUSH:
                PushRefTypePojo.CommonListOptions contractListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, contractListOptions);
                optionMap = BeanUtil.convertBean2Map(contractListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.CONTRACT_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.CONTRACT_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(contractListOptions);
                break;
            // 退货退款
            case REFUND_PUSH:
                PushRefTypePojo.CommonListOptions refundListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, refundListOptions);
                optionMap = BeanUtil.convertBean2Map(refundListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.REFUND_LIST.getType());

                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.REFUND_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(refundListOptions);
                break;
            // 工作报告
            case WORK_REPORT_PUSH:
                PushRefTypePojo.CommonListOptions workReportListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, workReportListOptions);
                optionMap = BeanUtil.convertBean2Map(workReportListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.WORK_REPORT_LIST.getType());
                pushRefTypePojo.setOptions(workReportListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.WORK_REPORT_LIST.getUrl(), optionMap));
                break;
            // 报价单
            case QUOTATION_PUSH:
                PushRefTypePojo.CommonListOptions quotationListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, quotationListOptions);
                optionMap = BeanUtil.convertBean2Map(quotationListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.QUOTATION_LIST.getType());
                pushRefTypePojo.setOptions(quotationListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.QUOTATION_LIST.getUrl(), optionMap));
                break;

            // 供应商
            case SUPPLIER_PUSH:
                PushRefTypePojo.CommonListOptions supplierListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, supplierListOptions);
                optionMap = BeanUtil.convertBean2Map(supplierListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.SUPPLIER_LIST.getType());
                pushRefTypePojo.setOptions(supplierListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.SUPPLIER_LIST.getUrl(), optionMap));
                break;
            // 供应商联系人
            case SUPPLIER_CONTACT_PUSH:
                PushRefTypePojo.CommonListOptions supplierContactListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, supplierContactListOptions);
                optionMap = BeanUtil.convertBean2Map(supplierContactListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.CONTACT_LIST.getType());
                pushRefTypePojo.setOptions(supplierContactListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.CONTACT_LIST.getUrl(), optionMap));
                break;
            // 采购合同
            case PURCHASE_PUSH:
                PushRefTypePojo.CommonListOptions purchaseContractListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, purchaseContractListOptions);
                optionMap = BeanUtil.convertBean2Map(purchaseContractListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PURCHASE_CONTRACT_LIST.getType());
                pushRefTypePojo.setOptions(purchaseContractListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PURCHASE_CONTRACT_LIST.getUrl(), optionMap));
                break;
            // 采购退货单
            case RETURNED_PURCHASE_PUSH:
                PushRefTypePojo.CommonListOptions purchaseReturnListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, purchaseReturnListOptions);
                optionMap = BeanUtil.convertBean2Map(purchaseReturnListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PURCHASE_RETURN_LIST.getType());
                pushRefTypePojo.setOptions(purchaseReturnListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PURCHASE_RETURN_LIST.getUrl(), optionMap));
                break;

            // 入库单
            case INSTOCK_PUSH:
                PushRefTypePojo.CommonListOptions inWarehouseListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, inWarehouseListOptions);
                optionMap = BeanUtil.convertBean2Map(inWarehouseListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.IN_WAREHOUSE_LIST.getType());
                pushRefTypePojo.setOptions(inWarehouseListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.IN_WAREHOUSE_LIST.getUrl(), optionMap));
                break;
            // 出库单
            case OUTSTOCK_PUSH:
                PushRefTypePojo.CommonListOptions outWarehouseListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, outWarehouseListOptions);
                optionMap = BeanUtil.convertBean2Map(outWarehouseListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.OUT_WAREHOUSE_LIST.getType());
                pushRefTypePojo.setOptions(outWarehouseListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.OUT_WAREHOUSE_LIST.getUrl(), optionMap));
                break;

            // 出入库单
            case ASSEMBLE_PUSH:
                PushRefTypePojo.CommonListOptions assembleListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, assembleListOptions);
                optionMap = BeanUtil.convertBean2Map(assembleListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.ASSEMBLE_LIST.getType());
                pushRefTypePojo.setOptions(assembleListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.ASSEMBLE_LIST.getUrl(), optionMap));
                break;
            // 调拔单
            case TRANSFER_PUSH:
                PushRefTypePojo.CommonListOptions transferListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, transferListOptions);
                optionMap = BeanUtil.convertBean2Map(transferListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.ALLOT_LIST.getType());
                pushRefTypePojo.setOptions(transferListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.ALLOT_LIST.getUrl(), optionMap));
                break;
            // 盘点单
            case INVENTORY_PUSH:
                PushRefTypePojo.CommonListOptions inventoryListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, inventoryListOptions);
                optionMap = BeanUtil.convertBean2Map(inventoryListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.INVENTORY_LIST.getType());
                pushRefTypePojo.setOptions(inventoryListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.INVENTORY_LIST.getUrl(), optionMap));
                break;

            // bom
            case BOMBILL_PUSH:
                PushRefTypePojo.CommonListOptions bomListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, bomListOptions);
                optionMap = BeanUtil.convertBean2Map(bomListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.BOM_LIST.getType());
                pushRefTypePojo.setOptions(bomListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.BOM_LIST.getUrl(), optionMap));
                break;
            // 生产单
            case PRODUCTION_ORDER_PUSH:
                PushRefTypePojo.CommonListOptions productionOrderListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, productionOrderListOptions);
                optionMap = BeanUtil.convertBean2Map(productionOrderListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PRODUCTION_ORDER_LIST.getType());
                pushRefTypePojo.setOptions(productionOrderListOptions);
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PRODUCTION_ORDER_LIST.getUrl(), optionMap));
                break;

            // 应收款
            case PAYMENT_PLAN_PUSH:
                PushRefTypePojo.CommonListOptions collectionOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, collectionOptions);
                optionMap = BeanUtil.convertBean2Map(collectionOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.COLLECTION_LIST.getType());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.COLLECTION_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(collectionOptions);
                break;
            // 付款计划
            case PAY_PLAN_PUSH:
                PushRefTypePojo.CommonListOptions paymentOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, paymentOptions);
                optionMap = BeanUtil.convertBean2Map(paymentOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PAYMENT_LIST.getType());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PAYMENT_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(paymentOptions);
                break;
            // 发票
            case INVOICE_PUSH:
                PushRefTypePojo.CommonListOptions invoiceOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, invoiceOptions);
                optionMap = BeanUtil.convertBean2Map(invoiceOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.INVOICE_LIST.getType());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.INVOICE_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(invoiceOptions);
                break;
                //TODO 进项发票 2020/4/23 宏晓说 智能助手进项发票消息推送这边 下次一起处理
            // 产品
            case PRODUCT_PUSH:
                PushRefTypePojo.CommonListOptions productOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, productOptions);
                optionMap = BeanUtil.convertBean2Map(productOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PRODUCT_MANEGEMENT_LIST.getType());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PRODUCT_MANEGEMENT_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(productOptions);
                break;
            // 库存预警
            case PRODUCT_STOCK_WARNING_PUSH:
                PushRefTypePojo.CommonListOptions stockWarningOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, stockWarningOptions);
                optionMap = BeanUtil.convertBean2Map(stockWarningOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PRODUCT_STOCK_LIST.getType());
                // defaultGroupCode = 81
                optionMap.put("defaultGroupCode", ListGroupEnum.WARNING_SEARCH.getCode());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PRODUCT_STOCK_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(stockWarningOptions);
                break;
            case PRODUCT_STOCK_GUARANTEE_PUSH:
                PushRefTypePojo.CommonListOptions stockGuarnteeOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, stockGuarnteeOptions);
                optionMap = BeanUtil.convertBean2Map(stockGuarnteeOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PRODUCT_STOCK_LIST.getType());
                // defaultGroupCode = 82
                optionMap.put("defaultGroupCode", ListGroupEnum.GUARANTEE_SEARCH.getCode());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PRODUCT_STOCK_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(stockGuarnteeOptions);
                break;

            case WAIT_PURCHASE_PUSH:
                PushRefTypePojo.CommonListOptions waitPurchaseListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, waitPurchaseListOptions);
                waitPurchaseListOptions.setSubBusinessType(XbbRefTypeEnum.WAIT_PURCHASE.getCode());
                optionMap = BeanUtil.convertBean2Map(waitPurchaseListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.WAIT_PURCHASE_CONTRACT_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.WAIT_PURCHASE_CONTRACT_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(waitPurchaseListOptions);
                break;
            case WAIT_PRODUCE_PUSH:
                PushRefTypePojo.CommonListOptions waitProduceListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, waitProduceListOptions);
                waitProduceListOptions.setSubBusinessType(XbbRefTypeEnum.WAIT_PRODUCE.getCode());
                optionMap = BeanUtil.convertBean2Map(waitProduceListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.WAIT_PRODUCTION_ORDER_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.WAIT_PRODUCTION_ORDER_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(waitProduceListOptions);
                break;
            case WAIT_OUTSTOCK_PUSH:
                PushRefTypePojo.CommonListOptions waitOutstockListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, waitOutstockListOptions);
                waitOutstockListOptions.setSubBusinessType(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode());
                optionMap = BeanUtil.convertBean2Map(waitOutstockListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.WAIT_OUT_WAREHOUSE_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.WAIT_OUT_WAREHOUSE_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(waitOutstockListOptions);
                break;
            case WAIT_INSTOCK_PUSH:
                PushRefTypePojo.CommonListOptions waitInstockListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, waitInstockListOptions);
                waitInstockListOptions.setSubBusinessType(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode());
                optionMap = BeanUtil.convertBean2Map(waitInstockListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.WAIT_IN_WAREHOUSE_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.WAIT_IN_WAREHOUSE_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(waitInstockListOptions);
                break;
            case MARKET_ACTIVITY_PUSH:
                PushRefTypePojo.CommonListOptions marketActivityListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, marketActivityListOptions);
                optionMap = BeanUtil.convertBean2Map(marketActivityListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.MARKET_ACTIVITY_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.MARKET_ACTIVITY_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(marketActivityListOptions);
                break;
            case CLUE_PUSH:
                PushRefTypePojo.CommonListOptions clueListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, clueListOptions);
                optionMap = BeanUtil.convertBean2Map(clueListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.CLUE_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.CLUE_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(clueListOptions);
                break;
            case PAAS_PUSH:
                PushRefTypePojo.CommonListOptions paasListOptions = new PushRefTypePojo.CommonListOptions();
                BeanUtil.copyProperties(options, paasListOptions);
                optionMap = BeanUtil.convertBean2Map(paasListOptions);
                pushRefTypePojo.setType(MessageWebPcUrlEnum.PAAS_LIST.getType());
                // 添加选择的formId
                optionMap.put("defaultFormId", options.getFormId());
                pushRefTypePojo.setPcUrl(UrlUtil.formatPcUrl(MessageWebPcUrlEnum.PAAS_LIST.getUrl(), optionMap));
                pushRefTypePojo.setOptions(paasListOptions);
                break;
            case UNKNOWN:
                break;
            default:
        }
        return JSON.toJSONString(pushRefTypePojo);
    }

    
}
